/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.compomics.dataprovider.control.logic.storage;

import com.compomics.dataprovider.model.fasta.FastaStream;
import java.io.File;
import java.io.IOException;

/**
 *
 * @author Kenneth
 */
public class FastaManager {

    private final File repositoryRoot;

    public FastaManager(File repositoryRoot) {
        this.repositoryRoot = repositoryRoot;
    }

    public void storeFasta(String originalName, FastaStream stream) throws IOException {
        File outputFile;
        originalName = originalName.replace(".fasta", "").replace(".FASTA", "");
        outputFile = new File(repositoryRoot, originalName + "/" + originalName+".fasta");
        outputFile.getParentFile().mkdirs();
        stream.save(outputFile, false);
    }

        public void storeFasta(String originalName,File outputfolder, FastaStream stream) throws IOException {
        File outputFile;
        if(outputfolder.equals(repositoryRoot)){
            outputfolder = new File(repositoryRoot,originalName);
        }
        originalName = originalName.replace(".fasta", "").replace(".FASTA", "");
        outputFile = new File(outputfolder,originalName+".fasta");
        outputFile.getParentFile().mkdirs();
        stream.save(outputFile, false);
    }
    
}
